<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="shortcut icon" href="/img/favicon.ico"/>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
  <link rel="stylesheet" href="/common/layuimini/public.css" media="all">
</head>
<body>
<input th:value="${commentId}" type="hidden" id="commentId">
<div class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label">删除原因:</label>
    <div class="layui-input-block deleteReason"></div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">普通文本域</label>
    <div class="layui-input-block">
      <textarea id="deleteRemark" placeholder="请输入内容" class="layui-textarea"></textarea>
    </div>
  </div>

  <div class="layui-btn-container" style="float: right">
    <button type="button" class="layui-btn layui-btn-normal" onclick="deleteReasonSubmit()">提交</button>
    <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:parent.layer.close(parent.layer.getFrameIndex(window.name))">取消</button>
  </div>
</div>
</body>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/common/xm-select/xm-select.js"></script>
<script type="text/javascript">
  window.onload = function () {
    //全局变量初始化xm-select
    var delReason;
    initDeleteSelect();
  }

  function deleteReasonSubmit(){
    //评论id
    var commentId = $("#commentId").val();
    //删除原因
    var delvalue = delReason.getValue('valueStr');
    var deleteRemark = $("#deleteRemark").val();

    if (delvalue == '' || delvalue == undefined){
      layer.msg("请选择删除原因",{icon:2,time:1000});
      return;
    }

    $.ajax({
      url: "/comment/admin/deleteById",
      type: "post",
      dataType: "json",
      data: {
        "commentId": commentId,
        "delvalue": delvalue,
        "deleteRemark": deleteRemark
      },
      success: function (res){
        if (res.state){
          parent.layui.table.reload('currentCategoryTable');
          layer.msg("删除成功",{icon:1,time:1000});
          parent.layer.close(parent.layer.getFrameIndex(window.name));
        }else {
          layer.msg("删除失败",{icon:2,time:1000})
        }
      }
    })
  }

  /*
  * 初始化删除原因框
  * */
  function initDeleteSelect(){
    delReason = xmSelect.render({
      el: '.deleteReason',
      radio: true,
      // filterable: true,//开启搜索模式
      height: '150px',//固定高度
      clickClose: true, //点击之后关闭
      model: {
        icon: 'hidden',
        label: {
          type: 'text'
        }
      },
      tips: '请选择',
      theme: {
        color: '#0081ff',
      },

      data: getDeleteReason()
    })
  }

  /*
  * 删除原因框查询数据
  * */
  function getDeleteReason(){
    var result;
    $.ajax({
      url: "/comment/admin/deleteReason",
      type: "get",
      async: false,
      success: function (res){
        if (res.state){
          result = res.data;
        }
      }
    })
    return result;
  }
</script>
</html>